package cn.com.bdqn.controller;

import cn.com.bdqn.entity.CstLinkman;
import cn.com.bdqn.service.CstLinkmanService;
import cn.com.bdqn.utils.ReturnData;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("cstLinkman")
@Api(tags = "客户联系人信息管理接口")
public class CstLinkmanController {

    @Autowired
    private CstLinkmanService cstLinkmanService;

    @Operation(summary = "修改客户联系人信息")
    @PostMapping("/updateCstLinkman")
    public ReturnData updateCstLinkman(CstLinkman cstLinkman){
        int result = cstLinkmanService.updateCstLinkman(cstLinkman);
        if (result > 0){
            return ReturnData.ok();
        }else {
            return ReturnData.currError("修改客户联系人信息异常");
        }
    }

    @Operation(summary = "新增客户联系人信息")
    @PostMapping("/addCstLinkman")
    public ReturnData addCstLinkman(CstLinkman cstLinkman){
        int result = cstLinkmanService.addCstLinkman(cstLinkman);
        if (result > 0){
            return ReturnData.ok();
        }else {
            return ReturnData.currError("新增客户联系人信息异常");
        }
    }

    @Operation(summary = "删除客户联系人信息")
    @PostMapping("/delCstLinkman")
    public ReturnData delCstLinkman(Long lkmId){
        int result = cstLinkmanService.delCstLinkman(lkmId);
        if (result > 0){
            return ReturnData.ok();
        }else {
            return ReturnData.currError("删除客户联系人信息异常");
        }
    }

    @Operation(summary = "根据客户编号查询相应的联系人信息")
    @PostMapping("/queryByLkmCustNo")
    public ReturnData queryByLkmCustNo(String lkmCustNo){
        try {
            List<CstLinkman> cstLinkmen = cstLinkmanService.queryByLkmCustNo(lkmCustNo);
            return ReturnData.ok().put("cstLinkmen",cstLinkmen);
        }catch (Exception e){
            return ReturnData.error();
        }

    }

    @Operation(summary = "根据联系人编号查询相应的联系人信息")
    @PostMapping("/queryByLkmId")
    public ReturnData queryByLkmId(Long lkmId){
        try{
            CstLinkman cstLinkmen = cstLinkmanService.queryByLkmId(lkmId);
            return ReturnData.ok().put("cstLinkmen",cstLinkmen);
        }catch (Exception e){
            e.printStackTrace();
            return ReturnData.currError("数据库查询异常");
        }
    }

}
